import {
  Column,
  Entity,
  OneToOne,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn
} from 'typeorm'
import {
  SexEnum,
  WedlockEnum,
  NationEnum,
  PoliticalAffiliationEnum,
  EducationLevelEnum,
  EngageFormEnum
} from 'src/types/staff'
import { Job } from 'src/modules/job/entities/job.entity'
import { Department } from 'src/modules/department/entities/department.entity'
import { WorkState } from 'src/modules/work-state/entities/work-state.entity'
import { App } from 'src/app.entity'

@Entity()
export class Staff extends App {
  @Column({ type: 'varchar', name: 'work_number' })
  workNumber: string
  @Column({ type: 'varchar', length: 11 })
  phone: string
  @Column({ type: 'varchar', default: '123456' })
  password: string
  @Column({ type: 'varchar', length: 5 })
  name: string
  @Column({ type: 'enum', enum: SexEnum, default: SexEnum['男'] }) // 0 女 1 男
  sex: number
  @Column({ type: 'varchar', length: 10, nullable: true })
  birthday: string
  @Column({ type: 'varchar', length: 18, name: 'id_card', nullable: true })
  idCard: string
  @Column({ type: 'enum', enum: WedlockEnum, default: WedlockEnum['未婚'] }) // 0 未婚 1 已婚 2 离婚 3 丧偶
  wedlock: number
  @Column({ type: 'enum', enum: NationEnum, nullable: true }) // 1
  nation: number
  @Column({ type: 'varchar', length: 20, name: 'native_place', nullable: true })
  nativePlace: string
  @Column({
    type: 'enum',
    enum: PoliticalAffiliationEnum,
    name: 'political_affiliation',
    default: PoliticalAffiliationEnum['群众']
  }) // 1
  politicalAffiliation: number
  @Column({ type: 'varchar', length: 50, nullable: true })
  email: string
  @Column({ type: 'varchar', length: 50, nullable: true })
  address: string
  @ManyToOne(() => Department, department => department.staff)
  @JoinColumn({ name: 'department_id' })
  department: Department
  @ManyToOne(() => Job, job => job.staff)
  @JoinColumn({ name: 'job_id' })
  job: Job
  @Column({ type: 'decimal', precision: 10, scale: 2, name: 'basis_salary' })
  basisSalary: number
  @Column({
    type: 'enum',
    enum: EngageFormEnum,
    default: EngageFormEnum['合同'],
    name: 'engage_form'
  }) // 0 合同 1 聘用 2 兼职
  engageForm: number
  @Column({
    type: 'enum',
    enum: EducationLevelEnum,
    default: EducationLevelEnum['其他'],
    name: 'education_level'
  }) // 1
  educationLevel: number
  @Column({ type: 'varchar', length: 10, nullable: true })
  specialty: string
  @Column({ type: 'varchar', length: 15, nullable: true })
  school: string
  @Column({ type: 'varchar', length: 10, name: 'in_date' })
  inDate: string
  @ManyToOne(() => WorkState)
  @JoinColumn({ name: 'work_state_id' })
  workState: WorkState
  @Column({ type: 'int', name: 'contract_date' })
  contractDate: number
  @Column({ type: 'varchar', length: 10, name: 'form_date', nullable: true })
  formDate: string
  @Column({ type: 'varchar', length: 10, name: 'leave_date', nullable: true })
  leaveDate: string
  @Column({ type: 'varchar', length: 10, name: 'begin_date', nullable: true })
  beginDate: string
  @Column({ type: 'varchar', length: 10, name: 'end_date', nullable: true })
  endDate: string
  @Column({ type: 'int', name: 'work_age', default: 0 })
  workAge: number
  @Column({
    type: 'varchar',
    length: 50,
    nullable: true,
    default: '1684986258940.png'
  })
  avatar: string
}
